library(foreign)
data <- read.dta("./research/assess/Exempt/city.dta")

table(data$Suits<0)
mean(data$Suits<0)
table(data$PRD>1)
mean(data$PRD>1)
table(data$PRD>1.03)
mean(data$PRD>1.03)
mean(data$PRD)
median(data$PRD)



summary(data$Exempt1)
quantile(data$Exempt1,c(.25,.50,.75))


dim(data)
pdf("./research/assess/Exempt/graphs/citymedian.pdf")
hist(data$Median,breaks=100,xlab="Median Assessment Ratio",main="Median",col="blue")
dev.off()

pdf("./research/assess/Exempt/graphs/cityCOD.pdf")
hist(data$COD[data$COD<100],breaks=100,xlab="Coefficient of Dispersion",main="COD",col="blue")
abline(v=15,col="red",lwd=3,lty="dashed")
dev.off()
mean(data$COD>15)

pdf("./research/assess/Exempt/graphs/cityPRD.pdf")
hist(data$PRD[data$PRD>.95&data$PRD<1.3],breaks=100,xlab="Price-Related Differential",main="PRD",col="blue")
abline(v=1.03,lty="dashed",lwd=3,col="red")
dev.off()
mean(data$PRD>1.03)
mean(data$PRD>1)
mean(data$PRD<0.98)

pdf("./research/assess/Exempt/graphs/citySuits.pdf")
hist(data$Suits,breaks=100,xlab="Suits Index",main="Suits Index",col="blue")
abline(v=0,lty="dashed",lwd=3,col="red")
dev.off()



pdf("./research/assess/Exempt/graphs/cityexempt.pdf")
hist(data$Exempt1[data$Exempt1<300000]/1000,breaks=100,xlab="Exemption ($1000)",col="blue",main="")
dev.off()

median(data$Exempt1/1000)
for (i in seq(10000,200000,10000)){
  sampvar <- data$Exempt1<=i
  cat(i,mean(sampvar),"\n")
}
o <- order(data$Exempt1)
Exempt <- data$Exempt1[o]/1000
n = nrow(data)
cumexempt <- cumsum(1:n)
cumexempt <- cumexempt/cumexempt[n]
sampvar <- Exempt<=1000
pdf("./research/assess/Exempt/graphs/citycumexempt.pdf")
plot(Exempt[sampvar],cumexempt[sampvar],main="Cumulative Distribution, Exemption ($1000)",xlab="Exemption ($1000)",
  ylab="Percentile",type="l",lwd=2)
dev.off()


data$pexempt <- data$Exempt1/data$mprice
summary(data$pexempt)
pdf("./research/assess/Exempt/graphs/citypexempt.pdf")
hist(data$pexempt[data$pexempt<1],breaks=100,xlab="Exemption as % of Median Sale Price",
  main="Exemption as % of Median Sale Price",col="blue")
dev.off()
median(data$pexempt)
median(data$pexempt[data$pexempt>0])




